function  [dataLearnAll, T, dataTestAll, TT] = start(sInput, sTest, Params_pre)
%sIntput (string) - soubor s cestmi k obrazkum na uceni
%sTest (string) - soubor s cestmi k obrazkum na testovani
%dataLearnAll - matice n x p s p sloupcovymi vektory z n dimenzionalniho prostoru,
%            kde vektory jsou vzory ktere se maji site naucit
%T - matice c x p s p sloupcovymi vektory z c dimenzionalniho prostoru, i ty vektor
%    obsahuje 0 na vsech mistech krome jednoho j-teho, na tomto ma hodnotu
%    1 a znamena ze i ty sloupcovy vektor z dataLearn patri do j-te tridy
%    c je pocet trid ktere se ma sit naucit  
%    matice vystupu
%dataTestAll - testovaci data stejny format jako dataLearnAll
%TT (Test Target) - vystupy pro testovaci data stejny format jako T
%Params_pre - parametry pro preprocessing (vektor struktur)


[imCellLearn,T, pathCellLearn] = io(sInput); % dataLearn
[imCellTest, TT, pathCellTest] = io(sTest); % test data

L = length(Params_pre);
dataLearnAll = cell(L,1);
dataTestAll = cell(L,1);

for i = 1:length(Params_pre)
    
    [dataLearn, imgHist] = fromCellData(imCellLearn, Params_pre(i), pathCellLearn);
    dataTest = fromCellData(imCellTest, Params_pre(i), pathCellTest, imgHist);

    %odstraneni (skoro) konstantnich radku
%    max_range = 0.001*mean(max(dataLearn,[], 2) - min(dataLearn,[], 2));
%    [dataLearn, PS] = removeconstantrows(dataLearn, max_range);
%    dataTest = removeconstantrows('apply', dataTest, PS);

    % PCA
    if Params_pre(i).usePCA
        PC = [];
        sPC = [sInput '_PC.mat'];
        if Params_pre(i).loadPCA && exist(sPC ,'file')   
            load(sPC,'PC');
        else
            PC = pcaEcon(dataLearn);
            if Params_pre(i).savePCA
                if size(PC,2) > 60
                    PC = PC(:,1:60);
                end
                save(sPC,'PC'); 
            end
        end

        %omezeni velikosti matice PCA, a tedy i vyslednych dat
        if size(PC,2) > Params_pre(i).nPCComponents
            PC = PC(:,1:Params_pre(i).nPCComponents);
        end

        dataLearn = PC' * dataLearn;
        dataTest = PC' * dataTest;
    end

    %normalizace stredni hodonty
    mn = mean(dataLearn,2); 
    dataLearn = dataLearn - repmat(mn,1,size(dataLearn,2));
    dataTest = dataTest - repmat(mn,1,size(dataLearn,2));

    %normalizece celkoveho rozptylu
    datastd = std(reshape(dataLearn, numel(dataLearn), 1));
    dataLearn = dataLearn / datastd;
    dataTest = dataTest / datastd;
    
    dataLearnAll{i} =  dataLearn;
    dataTestAll{i} =  dataTest;
end
end


